﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：TempCareUnitManagementInfo
// 文件功能描述：临时卡单位管理业务逻辑层
//
// 
// 创建标识：2012-05-17 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class TempCareUnitManagementInfo
    {
        /// <summary>
        /// 临时卡单位ID（主键）
        /// </summary>
        public int Dep_ID
        {
            get;
            set;
        }
        /// <summary>
        /// 临时卡单位名称
        /// </summary>
        public string deptName
        {
            get;
            set;
        }
        /// <summary>
        /// 临时卡单位编号
        /// </summary>
        public string Dep_No
        {
            get;
            set;
        }

        private DataAccessTempCareUnitManagement dar;
        private int TempCardUnitcount;
        public int _TempCardUnitcount
        {
            get { return TempCardUnitcount; }
        }
        public TempCareUnitManagementInfo(bool isgetcount)
        {
            dar = new DataAccessTempCareUnitManagement();
            if (isgetcount)
            {
                TempCardUnitcount = GetTempCardUnitcount();
            }
        }
        public TempCareUnitManagementInfo()
        { }

        /// <summary>
        /// 获取临时卡单位数量
        /// </summary>
        /// <returns></returns>
        private int GetTempCardUnitcount()
        {
            return dar.GetTempCardUnitcount();
        }

        /// <summary>
        /// 获取临时卡单位数量
        /// </summary>
        /// <returns></returns>
        public int GetTempCardUnitcount(string strquery)
        {
            return dar.GetTempCardUnitcount(strquery);
        }

        /// <summary>
        /// 获取临时卡单位信息（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<TempCareUnitManagementInfo> SelTempCardUnitInfo(int pagesize, int startindex, string strquery)
        {
            IList<TempCareUnitManagementInfo> templist = new List<TempCareUnitManagementInfo>();
            TempCareUnitManagementInfo tempinfo;
            DataSet ds = dar.SelTempCardUnitInfo(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                tempinfo = new TempCareUnitManagementInfo()
                {
                    Dep_ID = Convert.ToInt32(item["Dep_ID"]),
                    Dep_No = item["Dep_No"].ToString(),
                    deptName = item["deptName"].ToString()
                };
                templist.Add(tempinfo);
            }
            return templist;
        }

        /// <summary>
        /// 保存临时卡单位(新增界面下)
        /// </summary>
        /// <param name="men"></param>
        /// <returns></returns>
        public int SaveTempCardUnitAdd(TempCareUnitManagementInfo temp)
        {
            object[] gropara = new object[] { temp.deptName };
            return dar.SaveTempCardUnitAdd(gropara);
        }

        /// <summary>
        /// 删除临时卡单位
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public int DeleteTempCardUnit(string ID)
        {
            return dar.DeleteTempCardUnit(ID);
        }

        /// <summary>
        /// 保存临时卡单位(修改界面下)
        /// </summary>
        /// <param name="men"></param>
        /// <returns></returns>
        public int SaveTempCardUnitEdit(TempCareUnitManagementInfo temp)
        {
            object[] gropara = new object[] { temp.Dep_ID, temp.deptName };
            return dar.SaveTempCardUnitEdit(gropara);
        }

        /// <summary>
        /// 根据编号获取一条临时卡单位信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public TempCareUnitManagementInfo GetTempCardUnitInfoOne(string id)
        {
            dar = new DataAccessTempCareUnitManagement();
            DataSet ds = dar.GetTempCardUnitInfoOne(id);
            TempCareUnitManagementInfo info = new TempCareUnitManagementInfo();
            info.Dep_ID = int.Parse(ds.Tables[0].Rows[0]["Dep_ID"].ToString());
            info.Dep_No = ds.Tables[0].Rows[0]["Dep_No"].ToString();
            info.deptName = ds.Tables[0].Rows[0]["deptName"].ToString();
            return info;
        }
    }
}
